/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Marcacion.java
 *
 * Created on 29-jun-2012, 9:56:11
 */
package relojbiometrico;

import SecuGen.FDxSDK.jni.FDxDeviceInfoParam;
import SecuGen.FDxSDK.jni.FDxDeviceName;
import SecuGen.FDxSDK.jni.FDxError;
import SecuGen.FDxSDK.jni.FDxPortAddr;
import SecuGen.FDxSDK.jni.JFPLib;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;

/**
 *
 * @author InnoVajairo
 */
public class Marcacion extends java.awt.Dialog {

    private long deviceName;
    private long devicePort;
    private JFPLib fplib = null;
    private long ret;
    private boolean bLEDOn;
    private byte[] regMin1 = new byte[400];
    private byte[] regMin2 = new byte[400];
    private byte[] vrfMin = new byte[400];
    private Image img;
    private FDxDeviceInfoParam deviceInfo = new FDxDeviceInfoParam();
    private BufferedImage imgRegistration1;
    private BufferedImage imgRegistration2;
    private BufferedImage imgVerification;
    private boolean Captura_r1 = false;
    private boolean Captur_r1 = false;
    private boolean Captura_v1 = false;

    /** Creates new form Marcacion */
    public Marcacion(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        bLEDOn = false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagePanel1 = new com.mycsistemas.swingec.panel.ImagePanel();
        imagePanel2 = new com.mycsistemas.swingec.panel.ImagePanel();
        panelCurves1 = new org.edisoncor.gui.panel.PanelCurves();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        huella = new com.mycsistemas.swingec.panel.ImagePanel();
        jbtCapturar = new javax.swing.JButton();
        jbtCerrar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtamensajes = new javax.swing.JTextArea();
        jbtIniciar = new javax.swing.JButton();

        setIconImage(null);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });
        setLayout(null);

        imagePanel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/reloj/recursos/wallpaper hoja.jpg"))); // NOI18N
        imagePanel2.setLayout(null);

        panelCurves1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Georgia", 1, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Registro de Personal");
        panelCurves1.add(jLabel1);
        jLabel1.setBounds(70, 60, 250, 20);

        jPanel1.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(null);
        jPanel1.add(huella);
        huella.setBounds(10, 10, 160, 180);

        panelCurves1.add(jPanel1);
        jPanel1.setBounds(40, 100, 180, 200);

        jbtCapturar.setText("CAPTURAR");
        jbtCapturar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCapturarActionPerformed(evt);
            }
        });
        panelCurves1.add(jbtCapturar);
        jbtCapturar.setBounds(230, 240, 90, 60);

        jbtCerrar.setText("CERRAR");
        jbtCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCerrarActionPerformed(evt);
            }
        });
        panelCurves1.add(jbtCerrar);
        jbtCerrar.setBounds(230, 170, 90, 60);

        jtamensajes.setColumns(20);
        jtamensajes.setRows(5);
        jScrollPane1.setViewportView(jtamensajes);

        panelCurves1.add(jScrollPane1);
        jScrollPane1.setBounds(40, 306, 280, 50);

        jbtIniciar.setText("INICIAR");
        jbtIniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtIniciarActionPerformed(evt);
            }
        });
        panelCurves1.add(jbtIniciar);
        jbtIniciar.setBounds(230, 100, 90, 60);

        imagePanel2.add(panelCurves1);
        panelCurves1.setBounds(0, 0, 390, 380);

        add(imagePanel2);
        imagePanel2.setBounds(0, 0, 390, 390);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    public void desactivar_controles() {
        jbtCapturar.setEnabled(false);
        jbtCerrar.setEnabled(false);
    }

    public void activar_controles() {
        jbtCapturar.setEnabled(true);
        jbtCerrar.setEnabled(true);
    }
//CERRAR
private void jbtCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCerrarActionPerformed
// TODO add your handling code here:

    long idError = fplib.close();
    if (idError == FDxError.ERROR_NONE) {
        jtamensajes.setText("Cerrado() OK");
        desactivar_controles();
        jbtIniciar.setEnabled(true);

    } else {
        jtamensajes.setText("No se puede cerrar sesión");
    }
}//GEN-LAST:event_jbtCerrarActionPerformed

// INICIAR
private void jbtIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtIniciarActionPerformed
// TODO add your handling code here:


    fplib = new JFPLib(FDxDeviceName.CN_FDU02);
    devicePort = FDxPortAddr.AUTO_DETECT;
    ret = fplib.openDevice(devicePort);
    ret = fplib.getDeviceInfo(deviceInfo);

    if (ret == FDxError.ERROR_NONE) {
        jtamensajes.setText("Puerto Abierto OK");
        jbtIniciar.setEnabled(false);
        activar_controles();

    } else {
        jtamensajes.setText("No se pudo abrir. Error");
    }


}//GEN-LAST:event_jbtIniciarActionPerformed

// CAPTURAR
private void jbtCapturarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCapturarActionPerformed
// TODO add your handling code here:

    BufferedImage img1gray = new BufferedImage(260, 300, BufferedImage.TYPE_BYTE_GRAY);
    byte[] imageBuffer1 = ((java.awt.image.DataBufferByte) img1gray.getRaster().getDataBuffer()).getData();


    if (fplib != null) {
        bLEDOn = !bLEDOn;
        ret = fplib.getImage(imageBuffer1);
        if (ret == FDxError.ERROR_NONE) {
            huella.setIcon(new ImageIcon(img1gray));
            jtamensajes.setText("Capturado");
        } else {
            jtamensajes.setText("NO se pudo capturar");
        }
    } else {
        jtamensajes.setText("JLIB no ha sido iniciada");
    }
}//GEN-LAST:event_jbtCapturarActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                Marcacion dialog = new Marcacion(new java.awt.Frame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.mycsistemas.swingec.panel.ImagePanel huella;
    private com.mycsistemas.swingec.panel.ImagePanel imagePanel1;
    private com.mycsistemas.swingec.panel.ImagePanel imagePanel2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtCapturar;
    private javax.swing.JButton jbtCerrar;
    private javax.swing.JButton jbtIniciar;
    private javax.swing.JTextArea jtamensajes;
    private org.edisoncor.gui.panel.PanelCurves panelCurves1;
    // End of variables declaration//GEN-END:variables
}
